<template>
  <div style="padding-bottom: 60px">
    <div class="toptips mt24">
      <a-col :gutter="14">
        <a-alert message="合同变量自动代入花名册最新一份的合同信息，员工相关信息将作为合同内容中的真实信息。" banner closable />
      </a-col>
      <a-col :gutter="14">
        <a-button type="primary" :disabled="isBatch" class="mr16" @click="batchEdit">批量编辑</a-button>
        <a-button type="primary" :disabled="isBatch" class="mr16" @click="batchDelete">批量删除</a-button>
        <a-button icon="plus" type="primary" @click="addMember"> 添加员工 </a-button>
      </a-col>
    </div>
    <employee-select
      :show.sync="chooseStaffVisible"
      :default-selected-keys="defaultSelectedKeys"
      :selected-list.sync="currentSelectList"
      :template-id="templateId"
      @change="onMemberChange"
    />
    <a-table
      :loading="loading"
      :row-selection="{
        selectedRowKeys: selectedRowKeys,
        onChange: onSelectChange
      }"
      :columns="contractColumns"
      :data-source="contractlist"
      :scroll="{ x: contractColumns.length * 150 }"
      :customRow="rowClick"
      rowKey="empId"
      style="min-height: 300"
      :pagination="pagination"
      @change="handleTableChange"
    >
      <span slot="contractStartTime" slot-scope="text, item, idx">
        <a-date-picker
          v-model="item.contractStartTime"
          :allowClear="true"
          :disabledDate="disabledStartDate(item.contractEndTime)"
          placeholder="合同起始时间"
          style="width: 130px"
          @change="onChangeStart($event, item, idx)"
        />
      </span>
      <span slot="contractExpire" slot-scope="text, item, idx">
        <a-row type="flex">
          <a-col>
            <a-select
              v-model="item.contractExpire"
              :allowClear="true"
              :disabled="item.contractType === 'laborContractUnlimit'"
              placeholder="期限"
              style="width: 80px; margin-right: 8px"
              @change="onChangeNum($event, item, idx)"
            >
              <a-select-option v-for="(time, timeIndex) in item.leftTime ? item.leftTime : 11" :key="timeIndex + 1" :value="timeIndex + 1">
                {{ timeIndex + 1 }}
              </a-select-option>
            </a-select>
          </a-col>
          <a-col>
            <a-select
              v-model="item.timelimitType"
              :allowClear="true"
              :disabled="item.contractType === 'laborContractUnlimit'"
              placeholder="期限"
              style="width: 60px"
              @change="onChangeUnit($event, item, idx)"
            >
              <a-select-option v-for="(time, timeIndex) in rightTime" :key="timeIndex + 1" :value="timeIndex + 1">
                {{ time }}
              </a-select-option>
            </a-select>
          </a-col>
        </a-row>
      </span>
      <span slot="contractEndTime" slot-scope="text, item, idx">
        <a-date-picker
          v-model="item.contractEndTime"
          :disabled="item.contractType === 'laborContractUnlimit'"
          :disabledDate="disabledEndDate(item.contractStartTime)"
          :allowClear="true"
          placeholder="合同结束时间"
          style="width: 130px"
          @change="onChangeEnd($event, item, idx)"
        />
      </span>
      <span slot="contractType" slot-scope="text, item, idx">
        <a-dropdown>
          <a class="ant-dropdown-link">
            {{ getContractType(text) }}
          </a>
          <a-menu slot="overlay">
            <a-menu-item v-for="(menuitem, index) in contractTypeList" :key="index">
              <div style="display: flex; align-items: center" @click="onChangeType(menuitem, item, idx)">
                {{ menuitem.value }}
              </div>
            </a-menu-item>
          </a-menu>
        </a-dropdown>
      </span>
      <span slot="action" slot-scope="text, record">
        <a @click="edit(record)">编辑</a>
        <a-divider type="vertical" />
        <a @click="del(record)">删除</a>
      </span>
    </a-table>
    <div
      class="btnline bgc-white"
      :style="{
        position: 'fixed',
        width: 'auto',
        bottom: fixedBottom,
        right: '24px',
        zIndex: '10',
        left: fixedLeft
      }"
    >
      <a-button type="text" @click="backStep">上一步</a-button>
      <a-button type="primary" @click="nextStep">下一步</a-button>
    </div>
    <!-- 编辑 -->
    <a-drawer
      title="确认合同变量信息"
      :width="484"
      :visible="updateVisible"
      :body-style="{ paddingBottom: '80px' }"
      @close="updateVisible = false"
    >
      <a-form
        :form="contractForm"
        layout="vertical"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 16 }"
        :colon="true"
        hide-required-mark
        class="qrht"
      >
        <a-collapse :activeKey="activeKey" :bordered="false" style="background: #fff">
          <template #expandIcon="props">
            <a-icon type="caret-right" class="colorIcons" :rotate="props.isActive ? 90 : 0" />
          </template>
          <template v-for="item in conVariableMapArr">
            <a-collapse-panel
              v-if="showPanel(item.children)"
              :key="item.name"
              :header="item.name"
              class="bgc-white fs16 fw600"
              style="border: 0; overflow: hidden"
            >
              <a-row v-for="(item2, index2) in item.children" :key="index2">
                <a-row v-for="(val, key) in item2" :key="key.index">
                  <a-form-item
                    v-if="!hideItems.includes(key)"
                    :label="key"
                    align="center"
                    style="display: flex !important; align-items: center"
                  >
                    <a-input
                      v-decorator="[
                        key,
                        {
                          rules: [{ required: false, message: '请完善信息' }],
                          initialValue: val.content
                        }
                      ]"
                      :allowClear="true"
                      :max-length="key == '紧急联系人电话' || key == '联系电话' ? 11 : 200"
                      :placeholder="key == '工资支付方' ? '请填写 甲方 或者 用工单位 ' : key"
                    />
                  </a-form-item>
                </a-row>
              </a-row>
            </a-collapse-panel>
          </template>
        </a-collapse>
      </a-form>
      <div
        class="pv16 ph10 bgc-white ta-right"
        :style="{
          position: 'absolute',
          right: 0,
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e9e9e9',
          zIndex: 1
        }"
      >
        <a-button :style="{ marginRight: '8px' }" @click="updateVisible = false">取消</a-button>
        <a-button type="primary" @click="confirmTheContract">确认</a-button>
      </div>
    </a-drawer>
    <a-modal v-model="errStaffVisible" @ok="handleErrOk" title="未完善详情">
      <div style="overflow-y: scroll; height: 250px; white-space: pre">
        {{ errStaff }}
      </div>
    </a-modal>
    <BatchEdit v-model="batchEditVisible" @confirm="batchEditConfirm" />
  </div>
</template>
<script>
import { parseTime } from "@/utils/index";
import EmployeeSelect from "@/components/EmployeeSelect2/employeeSelect8";
import { isContainByString } from "@/utils/index";
const rightTime = ["年", "月"];
const rightTimeEn = ["years", "months"];
import {
  getEmpInfoListForContract,
  getVariableListMap,
  templateDetailReq,
  getCategoriesDetail,
  getContractdefault
} from "@/api/company/contract";
import moment from "moment";
import { contractTypeList, contractTypeDict, contractColumns, reviseCompanyName } from "../funcs";
import BatchEdit from "./batchEdit.vue";
export default {
  components: {
    EmployeeSelect,
    BatchEdit
  },
  props: {
    contractlist: {
      type: Array,
      required: true
    },
    templateId: {
      type: Number,
      default: 0
    },
    enterpriseName: {
      type: String,
      default: ""
    },
    variableListMap: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      errListCopy2: [],
      loading: false,
      errListCopy: [],
      rightTime,
      isContainByString,
      parseTime,
      contractColumns,
      contractTypeList,
      selectedRowKeys: [],
      contractForm: this.$form.createForm(this),
      isBatch: true,
      updateVisible: false,
      chooseStaffVisible: false,
      currentContract: {},
      currentCategory: {},
      defaultSelectedKeys: [],
      conVariableMapArr: [],
      errStaff: "",
      errStaffVisible: false,
      currentItem: undefined,
      activeKey: ["0"],
      pagination: {
        pageSize: 10,
        total: 0,
        size: "default",
        current: 1,
        showTotal: (total) => `共 ${total} 条`,
        showQuickJumper: true,
        showSizeChanger: true,
        pageSizeOptions: ["10", "20", "50", "100"]
      },
      batchEditVisible: false,
      hideItems: ["签署确认时间", "合同开始时间", "合同结束时间", "合同期限"],
      currentSelectList: []
    };
  },
  computed: {
    fixedLeft() {
      const isOpened = this.$store.state.app.sidebar.opened;
      return `${isOpened ? 210 + 24 : 64 + 24}px`;
    },
    fixedBottom() {
      const mainWidth = this.$store.state.app.mainWidth;
      const isOpened = this.$store.state.app.sidebar.opened;
      const contentWidth = mainWidth - (isOpened ? 210 : 64) - 48;
      const isScrolling = contentWidth < 1000;
      return `${isScrolling ? 9 + 24 : 24}px`;
    }
  },
  watch: {
    contractlist: {
      handler(newVal) {
        this.defaultSelectedKeys = newVal.map((item) => item.empId);
        this.currentSelectList = newVal;
      },
      immediate: true
    }
  },
  mounted() {
    this.getVariableListMap();
    this.getDetailByTemplateId();
  },
  methods: {
    disabledStartDate(endValue) {
      return function (val) {
        if (!val || !endValue) {
          return false;
        }
        return val.valueOf() > endValue.valueOf();
      };
    },
    disabledEndDate(startValue) {
      return function (val) {
        if (!val || !startValue) {
          return false;
        }
        return val.valueOf() < startValue.valueOf();
      };
    },
    showPanel(arr) {
      const notHideItems = arr.filter((item) => !this.hideItems.includes(Object.keys(item)[0]));
      return notHideItems.length > 0;
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
    },
    rowClick(record, index) {
      return {
        on: {
          click: () => {
            this.currentItem = record;
          }
        }
      };
    },
    onChangeStart(date, item, idx) {
      const tempItem = { ...item };
      tempItem.contractStartTime = date;
      tempItem.conVariableMap.forEach((li) => {
        Object.keys(li).forEach((v) => {
          if (li[v].name === "合同开始时间") {
            li[v].content = tempItem.contractStartTime ? moment(tempItem.contractStartTime).format("YYYY-MM-DD") : null;
          }
        });
      });
      if (
        tempItem.contractType !== "laborContractUnlimit" &&
        tempItem.timelimitType &&
        tempItem.contractExpire &&
        tempItem.contractStartTime
      ) {
        const a = tempItem.contractStartTime.clone();
        tempItem.contractEndTime = a.add(tempItem.contractExpire, rightTimeEn[tempItem.timelimitType - 1]).add(-1, "days");
        tempItem.conVariableMap.forEach((li) => {
          Object.keys(li).forEach((v) => {
            if (li[v].name === "合同结束时间") {
              li[v].content = moment(tempItem.contractEndTime).format("YYYY-MM-DD");
            }
          });
        });
      }
      const contractListTemp = [...this.contractlist];
      contractListTemp[idx] = tempItem;
      this.$emit("update:contractlist", contractListTemp);
    },
    onChangeNum(val, item, idx) {
      const tempItem = { ...item };
      tempItem.contractExpire = val;
      if (tempItem.contractStartTime && tempItem.timelimitType && val) {
        const a = tempItem.contractStartTime.clone();
        tempItem.contractEndTime = a.add(tempItem.contractExpire, rightTimeEn[tempItem.timelimitType - 1]).add(-1, "days");
        tempItem.conVariableMap.forEach((li) => {
          Object.keys(li).forEach((v) => {
            if (li[v].name === "合同结束时间") {
              li[v].content = moment(tempItem.contractEndTime).format("YYYY-MM-DD");
            }
          });
        });
      }
      tempItem.conVariableMap.forEach((li) => {
        Object.keys(li).forEach((v) => {
          if (li[v].name === "合同期限") {
            li[v].content =
              (tempItem.contractExpire ? tempItem.contractExpire : "") +
              (tempItem.timelimitType ? rightTime[tempItem.timelimitType - 1] : "");
          }
        });
      });
      const contractListTemp = [...this.contractlist];
      contractListTemp[idx] = tempItem;
      this.$emit("update:contractlist", contractListTemp);
    },
    onChangeUnit(val, item, idx) {
      const tempItem = { ...item };
      tempItem.timelimitType = val;
      if (tempItem.contractStartTime && tempItem.contractExpire && val) {
        const a = tempItem.contractStartTime.clone();
        tempItem.contractEndTime = a.add(tempItem.contractExpire, rightTimeEn[tempItem.timelimitType - 1]).add(-1, "days");
        tempItem.conVariableMap.forEach((li) => {
          Object.keys(li).forEach((v) => {
            if (li[v].name === "合同结束时间") {
              li[v].content = moment(tempItem.contractEndTime).format("YYYY-MM-DD");
            }
          });
        });
      }
      tempItem.conVariableMap.forEach((li) => {
        Object.keys(li).forEach((v) => {
          if (li[v].name === "合同期限") {
            li[v].content =
              (tempItem.contractExpire ? tempItem.contractExpire : "") +
              (tempItem.timelimitType ? rightTime[tempItem.timelimitType - 1] : "");
          }
        });
      });
      const contractListTemp = [...this.contractlist];
      contractListTemp[idx] = tempItem;
      this.$emit("update:contractlist", contractListTemp);
    },
    onChangeEnd(date, item, idx) {
      const tempItem = { ...item };
      tempItem.contractEndTime = date;
      tempItem.conVariableMap.forEach((li) => {
        Object.keys(li).forEach((v) => {
          if (li[v].name === "合同结束时间") {
            li[v].content = moment(tempItem.contractEndTime).format("YYYY-MM-DD");
          }
        });
      });
      const contractListTemp = [...this.contractlist];
      contractListTemp[idx] = tempItem;
      this.$emit("update:contractlist", contractListTemp);
    },
    async onChangeType(meunItem, item, idx) {
      const tempItem = { ...item };
      tempItem.contractType = meunItem.key;
      await getContractdefault({ empId: tempItem.empId, type: tempItem.contractType }).then((res) => {
        if (res.data) {
          tempItem.contractStartTime = res.data.startTime ? moment(res.data.startTime) : null;
          tempItem.contractEndTime = res.data.endTime ? moment(res.data.endTime) : null;
          // 期限
          if (res.data.termMonth) {
            tempItem.contractExpire = res.data.termMonth;
            tempItem.timelimitType = 2;
          } else if (res.data.termYear) {
            tempItem.contractExpire = res.data.termYear;
            tempItem.timelimitType = 1;
          } else {
            tempItem.contractExpire = null;
            tempItem.timelimitType = null;
          }
          tempItem.conVariableMap.forEach((li) => {
            Object.keys(li).forEach((v) => {
              if (li[v].name === "合同开始时间") {
                li[v].content = tempItem.contractStartTime ? moment(tempItem.contractStartTime).format("YYYY-MM-DD") : null;
              }
              if (li[v].name === "合同结束时间") {
                li[v].content = tempItem.contractEndTime ? moment(tempItem.contractEndTime).format("YYYY-MM-DD") : null;
              }
              if (li[v].name === "合同期限") {
                if (res.data.termMonth) {
                  li[v].content = res.data.termMonth + "月";
                } else if (res.data.termYear) {
                  li[v].content = res.data.termYear + "年";
                } else {
                  li[v].content = null;
                }
              }
            });
          });
        }
      });
      if (tempItem.contractType === "laborContractUnlimit") {
        // 无固定期限劳动合同
        tempItem.contractExpire = null; // 合同期限
        tempItem.timelimitType = null;
        tempItem.contractEndTime = null;

        tempItem.conVariableMap.forEach((li) => {
          Object.keys(li).forEach((v) => {
            if (li[v].name === "合同期限") {
              li[v].content = null;
            }
            if (li[v].name === "合同结束时间") {
              li[v].content = null;
            }
          });
        });
      }
      const contractListTemp = [...this.contractlist];
      contractListTemp[idx] = tempItem;
      this.$emit("update:contractlist", contractListTemp);
    },
    getDetailByTemplateId() {
      templateDetailReq(this.templateId).then((res) => {
        getCategoriesDetail(res.data.categoryId).then((res) => {
          this.currentCategory = res.data;
        });
      });
    },
    onMemberChange(selectedList) {
      this.loading = true;
      getEmpInfoListForContract({
        companyId: this.$store.state.hr.companyId,
        templateId: this.templateId,
        empIdList: selectedList.map((item) => item.id)
      }).then((res) => {
        // 字符串合同时间转 date类型
        res.data.forEach((item) => {
          item.contractStartTime = item.contractStartTime ? moment(item.contractStartTime) : null;
          item.contractEndTime = item.contractEndTime ? moment(item.contractEndTime) : null;
          if (item.contractExpire) {
            const ex = item.contractExpire.split(" ");
            item.contractExpire = parseInt(ex[0]);
            if (ex[1] === "年") {
              item.timelimitType = 1;
            } else if (ex[1] === "月") {
              item.timelimitType = 2;
            }
          }
        });
        const list = reviseCompanyName(res.data, this.enterpriseName, this.contractlist);
        this.$emit("update:contractlist", list);
        this.loading = false;
      });
    },
    addMember() {
      this.chooseStaffVisible = true;
    },
    getVariableListMap() {
      getVariableListMap(this.templateId).then((res) => {
        if (!this.variableListMap.length) {
          this.$emit("update:variableListMap", res.data);
        }
      });
    },
    batchEditConfirm(values) {
      if (Object.keys(values).length > 0) {
        const contractListTemp = JSON.parse(JSON.stringify(this.contractlist));
        this.selectedRowKeys.forEach((key) => {
          contractListTemp.forEach((item) => {
            if (item.id === key) {
              if (values.contractStartTime) {
                item.contractStartTime = values.contractStartTime;
              }
              if (values.contractType) {
                item.contractType = values.contractType;
              }
              if (values.contractType !== "laborContractUnlimit" && item.contractType !== "laborContractUnlimit") {
                if (values.contractExpire) {
                  item.contractExpire = values.contractExpire;
                }
                if (values.timelimitType) {
                  item.timelimitType = values.timelimitType;
                }
                if (values.contractEndTime) {
                  item.contractEndTime = values.contractEndTime;
                }
              } else {
                item.contractEndTime = null;
                item.contractExpire = null;
                item.timelimitType = null;
              }
              item.conVariableMap.forEach((li) => {
                Object.keys(li).forEach((v) => {
                  if (values.contractStartTime && li[v].name === "合同开始时间") {
                    li[v].content = moment(values.contractStartTime).format("YYYY-MM-DD");
                  }
                  if (values.contractType !== "laborContractUnlimit" && item.contractType !== "laborContractUnlimit") {
                    if (values.contractEndTime && li[v].name === "合同结束时间") {
                      li[v].content = moment(values.contractEndTime).format("YYYY-MM-DD");
                    }
                    if (li[v].name === "合同期限") {
                      li[v].content =
                        (values.contractExpire ? values.contractExpire : "") +
                        (values.timelimitType ? rightTime[values.timelimitType - 1] : "");
                    }
                  } else {
                    if (values.contractEndTime && li[v].name === "合同结束时间") {
                      li[v].content = null;
                    }
                    if (li[v].name === "合同期限") {
                      li[v].content = null;
                    }
                  }
                });
              });
            }
          });
        });
        this.$emit("update:contractlist", contractListTemp);
      }
    },
    batchEdit() {
      this.batchEditVisible = true;
    },
    batchDelete() {
      const contractListTemp = [].concat(this.contractlist);
      this.selectedRowKeys.forEach((key) => {
        contractListTemp.forEach((item, i) => {
          if (item.empId === key) {
            contractListTemp.splice(i, 1);
          }
        });
      });
      this.$emit("update:contractlist", contractListTemp);
      this.selectedRowKeys = [];
      this.isBatch = true;
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys;
      if (this.selectedRowKeys.length >= 1) {
        this.isBatch = false;
      } else {
        this.isBatch = true;
      }
    },
    edit(record) {
      this.contractForm.resetFields();
      this.updateVisible = true;
      this.currentContract = {};
      this.conVariableMapArr = [];
      if (record.conVariableMap) {
        this.conVariableMapArr = this.filterData(record.conVariableMap);
      }
      this.currentContract = record;
    },
    filterData(data) {
      const jsonArr = [];
      // 企业信息
      const enterpriseVars = data.filter((item) => item[Object.keys(item)[0]].moduleCode === "enterprise");
      if (enterpriseVars.length > 0) jsonArr.push({ name: "企业信息", children: enterpriseVars });
      // 基本信息
      const basicArr = data.filter((item) => item[Object.keys(item)[0]].moduleCode === "basic");
      if (basicArr.length > 0) jsonArr.push({ name: "基本信息", children: basicArr });
      // 身份信息
      const empIdCardArr = data.filter((item) => item[Object.keys(item)[0]].moduleCode === "empIdCard");
      if (empIdCardArr.length > 0) jsonArr.push({ name: "身份信息", children: empIdCardArr });
      // 联系信息
      const contactArr = data.filter((item) => item[Object.keys(item)[0]].moduleCode === "contact");
      if (contactArr.length > 0) jsonArr.push({ name: "联系信息", children: contactArr });
      // 家庭成员
      const empFamilyArr = data.filter((item) => item[Object.keys(item)[0]].moduleCode === "empFamily");
      if (empFamilyArr.length > 0) jsonArr.push({ name: "家庭成员", children: empFamilyArr });
      // 紧急联系人
      const empContactsArr = data.filter((item) => item[Object.keys(item)[0]].moduleCode === "empContacts");
      if (empContactsArr.length > 0) jsonArr.push({ name: "紧急联系人", children: empContactsArr });
      // 教育经历
      const empEducationArr = data.filter((item) => item[Object.keys(item)[0]].moduleCode === "empEducation");
      if (empEducationArr.length > 0) jsonArr.push({ name: "教育经历", children: empEducationArr });
      // 合同信息
      const contractVars = data.filter((item) => item[Object.keys(item)[0]].moduleCode === "contract");
      if (contractVars.length > 0) jsonArr.push({ name: "合同信息", children: contractVars });
      // 自定义信息
      const additionalArr = data.filter((item) => item[Object.keys(item)[0]].moduleCode === "additional");
      if (additionalArr.length > 0) jsonArr.push({ name: "自定义信息", children: additionalArr });
      return jsonArr;
    },
    del(record) {
      const contractListTemp = [].concat(this.contractlist);
      contractListTemp.forEach((item, i) => {
        if (item.phone === record.phone) {
          contractListTemp.splice(i, 1);
        }
      });
      this.selectedRowKeys = [];
      this.isBatch = true;
      this.$emit("update:contractlist", contractListTemp);
    },
    confirmTheContract(e) {
      this.contractForm.validateFields((err, values) => {
        if (!err) {
          const valueKeys = Object.keys(values);
          const contractListTemp = JSON.parse(JSON.stringify(this.contractlist));
          contractListTemp.forEach((item) => {
            if (item.id === this.currentContract.id) {
              item.conVariableMap.forEach((variable, index) => {
                Object.keys(variable).forEach((v) => {
                  if (!this.hideItems.includes(v) && valueKeys.includes(v)) {
                    item.conVariableMap[index][v].content = values[v] || null;
                  }
                });
              });
            }
            this.updateVisible = false;
            this.contractForm.resetFields();
          });
          this.$emit("update:contractlist", contractListTemp);
        }
      });
    },
    nextStep() {
      if (this.contractlist.length > 0) {
        const errList = [];
        this.contractlist.forEach((item, index) => {
          if (item.contractStartTime && item.contractEndTime) {
            if (moment(item.contractStartTime).valueOf() > moment(item.contractEndTime).valueOf()) {
              errList.push(index);
            }
          }
        });
        if (errList.length > 0) {
          this.$message.error("第 " + errList.join(", ") + " 条合同开始时间大于结束时间");
          return false;
        }
        const flag = this.judgeErrStaff();
        if (!flag) {
          this.errStaffVisible = true;
        } else {
          this.$emit("current", 2);
        }
      } else {
        this.$message.warning("请添加合同签署员工");
      }
    },
    unique(arr) {
      return Array.from(new Set(arr));
    },
    judgeErrStaff() {
      let flag = true;
      const errList = [];
      this.errListCopy2 = [];
      this.errStaff = [];
      this.contractlist.forEach((item, index) => {
        this.errListCopy = [];
        item.conVariableMap.forEach((item2, index2) => {
          Object.keys(item2).forEach((v) => {
            if (
              item2[v].name !== "合同结束时间" &&
              item2[v].name !== "合同期限" &&
              item2[v].name !== "合同开始时间" &&
              (item2[v].content === null || item2[v].content.replace(/\s+/g, "") === "")
            ) {
              this.errListCopy.push(item.name + "的" + item2[v].name);
              flag = false;
            }
          });
        });
        if (item.contractType === null || item.contractType === "null" || item.contractType.replace(/\s+/g, "") === "") {
          // 无合同期限
          this.errListCopy.push(item.name + "的合同类型");
          flag = false;
        }
        if (this.errListCopy.length > 2) {
          this.errListCopy.forEach((item3, index3) => {
            if (index3 === this.errListCopy.length - 1) {
              item3 = item3.split("的")[1];
              this.errListCopy2.push(item3 + "信息未完善。" + "\n");
            } else if (index3 !== 0) {
              item3 = item3.split("的")[1];
              this.errListCopy2.push(item3 + "、");
            }
            if (index3 === 0) {
              this.errListCopy2.push(item3 + "、");
            }
          });
        } else if (this.errListCopy.length === 1) {
          this.errListCopy.forEach((item3, index3) => {
            if (index3 === 0) {
              this.errListCopy2.push(item3 + "信息未完善。" + "\n");
            }
          });
        } else if (this.errListCopy.length === 2) {
          this.errListCopy.forEach((item3, index3) => {
            if (index3 === 0) {
              this.errListCopy2.push(item3 + "、");
            } else if (index3 === 1) {
              item3 = item3.split("的")[1];
              this.errListCopy2.push(item3 + "信息未完善。" + "\n");
            }
          });
        }
      });
      this.errListCopy2.forEach((item, index) => {
        if (index !== errList.length - 1) {
          this.errStaff += `${item}`;
        } else {
          this.errStaff += item;
        }
      });
      return flag;
    },
    handleErrOk() {
      this.$emit("update:contractlist", this.contractlist);
      this.$emit("current", 2);
    },
    backStep() {
      this.$emit("current", 0);
    },
    getContractType(contractType) {
      if (!contractType) {
        return "请选择合同类型";
      } else {
        return contractTypeDict[contractType] || "--";
      }
    }
  }
};
</script>
<style lang="scss">
.ant-drawer-title {
  border-left: 4px solid var(--primary);
  padding-left: 10px;
}
.ant-drawer-body {
  max-height: 90vh;
  overflow: auto;
}
.ant-form-vertical .ant-form-item-label,
.ant-col-24.ant-form-item-label,
.ant-col-xl-24.ant-form-item-label {
  text-align: left;
  padding: 0;
}
.toptips {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.contractpage {
  width: 80%;
  min-height: 400px;
  max-height: 500px;
  overflow: auto;
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  margin: 0 auto;
  padding: 20px;
  .ant-form-vertical .ant-form-item-label,
  .ant-col-24.ant-form-item-label,
  .ant-col-xl-24.ant-form-item-label {
    text-align: right;
    padding-right: 10px;
  }
}
.qrht .ant-form-item-label > label {
  font-weight: 400;
}
.qrht .ant-collapse-content-box {
  padding: 0 16px;
}
</style>
